package com.cda.api;

import com.cda.entity.Person;
import com.cda.utils.RestClientUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.text.SimpleDateFormat;

@Controller
@RequestMapping(value="/")
public class TestFaceApi {


    @Autowired
    FaceApi faceApi;

    @RequestMapping("setDeviceKey")
    @ResponseBody
    public void setDeviceKey() throws Exception{
        System.out.println(  faceApi.setDeviceKey() );

    }

    @RequestMapping("getVisitorConfig")
    @ResponseBody
    public void getVisitorConfig() throws Exception{

        System.out.println(faceApi.getVisitorConfig("abc"));

    }


    @RequestMapping("getDeviceInfo")
    @ResponseBody
    public String getDeviceInfo() throws Exception{

       String result = faceApi.getDeviceInfo();
       System.out.println(result);
       return result;

    }


    @RequestMapping("photo")
    @ResponseBody
    public String photo() throws Exception{

        return faceApi.photo("最帅最美的人，请抬头","谢谢",1) ;

    }

    @RequestMapping("removePerson")
    @ResponseBody
    public String removePerson() throws Exception{

        return faceApi.removePerson ("") ;

    }

    @RequestMapping("getRecordCallback")
    @ResponseBody
    public String getRecordCallback() throws Exception{

      return faceApi.getRecordCallback() ;

    }

    @RequestMapping("setHeartBeat")
    @ResponseBody
    public String setHeartBeat() throws Exception{

        String url = "http://192.168.1.102:8080/face/listRecord";
        return faceApi.setHeartBeat(url,300.0)  ;

    }

    @RequestMapping("removeRecord")
    @ResponseBody
    public String removeRecord() throws Exception{

        long time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse("2019-04-04 15:04:00").getTime() / 1000;
        return faceApi.removeRecord(time)  ;

    }

    @RequestMapping("uploadRecord")
    @ResponseBody
    public String uploadRecord() throws Exception{

        Person p = new Person();
        p.setId("001");//ID,验证人员唯一性的字段作
        p.setName("人脸识别成功");//人员的名字
        p.setIC_NO("1001");//为维根号发送到闸机
        p.setID_NO("440923199106284111");//	员工身份证号
        p.setPhoto("bvvvvvvvvvvvvvvvvvv");
         faceApi.uploadRecord(p);
         return null;
    }

    @RequestMapping("getHeartBeat")
    @ResponseBody
    public String getHeartBeat() throws Exception{

        return faceApi.getHeartBeat();
    }
}
